#include<bits/stdc++.h>
#include<math.h>
#define ll long long int
#define ull unsigned long long int
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree< ll, null_type, less<ll >, rb_tree_tag, tree_order_statistics_node_update> order_set;
#define fbo find_by_order
#define ook order_of_key
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define print(res) cout<<#res<<" = ";for(auto x:res) cout<<x<<" "; cout<<endl
#define see(res) cout<<#res<<" = "<<res<<endl
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pf push_front
#define pb push_back
#define NL printf("\n")
#define YES printf("YES\n")
#define NO printf("NO\n")
#define Yes printf("Yes\n")
#define No printf("No\n")
#define tc int tc;scanf("%d",&tc);for(int cs=1;cs<=tc;cs++)
const ll mxn=2e6+6;
const ll mod=1e9+7;
const ll N=2e5+10;
int main( )
{
tc
{
ll n ;
cin>>n ;
map<ll,ll>m1;
map<ll,ll>m2;
ll a[n+10] ;
for(ll i=1 ; i<=n ; i++)
{
cin>>a[i];
m1[a[i]]++ ;
}
ll ans = 0;
ll extra = 0 ;
ll cnt = 1;
for(ll i=n ; i>=1 ; i--)
{
if(m2[a[i]]) ++extra;
--m1[a[i]];
++m2[a[i]];
if(m1[a[i]]==0) ans+=(cnt-extra);
++cnt;
}
cout<<ans<<endl;
cout<<endl;
}
return 0;
}
//printf("Case %d: ",cs);
733. Flood Fill | 206. Reverse Linked List |
83. Remove Duplicates from Sorted List | 116. Populating Next Right Pointers in Each Node |
145. Binary Tree Postorder Traversal | 94. Binary Tree Inorder Traversal |
101. Symmetric Tree | 77. Combinations |
46. Permutations | 226. Invert Binary Tree |
112. Path Sum | 1556A - A Variety of Operations |
136. Single Number | 169. Majority Element |
119. Pascal's Triangle II | 409. Longest Palindrome |
1574A - Regular Bracket Sequences | 1574B - Combinatorics Homework |
1567A - Domino Disaster | 1593A - Elections |
1607A - Linear Keyboard | EQUALCOIN Equal Coins |
XOREQN Xor Equation | MAKEPAL Weird Palindrome Making |
HILLSEQ Hill Sequence | MAXBRIDGE Maximise the bridges |
WLDRPL Wildcard Replacement | 1221. Split a String in Balanced Strings |
1002. Find Common Characters | 1602A - Two Subsequences |